package convertor

import "unsafe"

// 这样int32转字符串的效率是最快的，没有之一
// 其他方法的比较参考： https://stackoverflow.com/questions/39442167/convert-int32-to-string-in-golang
func int32toString(n int32) string {
	buf := [11]byte{}
	pos := len(buf)
	i := int64(n)
	signed := i < 0
	if signed {
		i = -i
	}
	for {
		pos--
		buf[pos], i = '0'+byte(i%10), i/10
		if i == 0 {
			if signed {
				pos--
				buf[pos] = '-'
			}
			return string(buf[pos:])
		}
	}
}

//bool 类型转 int
func intToBool(d bool) int {
	if d == true {
		return 0
	} else {
		return 1
	}
}

//bool 类型转 float64
func floatToBool(d bool) float64 {
	if d == true {
		return 0
	} else {
		return 1
	}
}

//针对32位机器
//获取cpu位数
func int64Bit(d int64) int {
	bit := 32 << (^uint(0) >> 63)

	switch bit {
	case 32:
		idPointer := *((*int)(unsafe.Pointer(&d)))
		return idPointer
	case 64:
		return int(d)
	}
	panic("就是想恐慌")
	return 0
}
